<?php

/*

  Action - Attack	$4

  +2 Cards
  Discard 2 cards. Each other player may reveal a Bane card from his hand. If he doesn’t, he gains a Curse.
  Setup:  Add an extra Kingdom card pile costing $2 or $3 to the Supply. Cards from that pile are Bane cards.

 */

class YoungWitch extends Card implements iAction, iKingdom, iAttack, iCornucopia {

    public function __construct() {
        parent::__construct("Young Witch", 4);
        $this->undoPlay = false;
        $this->undoBuy = true;
    }

    public function getDescription() {
        return array(
            "+2 Cards",
            "Discard 2 cards. Each other player may reveal a Bane card from his hand. If he doesn’t, he gains a Curse.",
            "Setup:  Add an extra Kingdom card pile costing $2 or $3 to the Supply. Cards from that pile are Bane cards.");
    }
    
        public function getDisplayName($quantity = 1) {
        if ($quantity == 1) {
            return "Young Witch";
        }
        return $quantity." Young Witches";
    }

    public function play(Game $game, $isRealCard) {
        $drawed_cards = $game->drawCards(2);
        ScreenDisplay::addScreenMessage($game, true, "draw  " . nicePrint($drawed_cards), "draws " . sizeof($drawed_cards). " cards");
        $game->attack($this);

        $bane = $game->getBaneCard();

        //do all the stuff with bain thing
        $names = $game->getOtherPlayersNames(true);
        foreach ($names as $name) {

            $bane_found = $game->getCardInHand($bane, $name);

            if ($bane_found) {
                $options = array(new Option(1, "Yes"), new Option(2, "No"));
                $output = MySocket::GetUserReply($game, Input_ChooseOne, $options, 1, 1, null, "Reveal bane (" . $bane->getValue() . ") card?", $name, true);
            } else {
                $curse = $game->moveCardFromPileToPile("Curse", BoardCards, DiscardPile, $name);
                ScreenDisplay::addScreenMessage($game, true, "gain " . nicePrint($curse), "gains " . ScreenDisplay::$LMSG, $name);
            }
        }

        //discard 2 cards
        $cards = $game->getPlayHand();
        if (sizeof($cards) > 2) {
            $output = MySocket::GetUserReply($game, Input_ChooseMany, $cards, 2, 2, null, "Choose 2 cards to discard");
            ScreenDisplay::addScreenMessage($game, true, "discard  " . nicePrint($output), "discards " . sizeof($output) . " cards");
            foreach ($output as $p) {
                $game->moveCardFromPileToPile($p, PlayHand, DiscardPile);
            }
        } else {
            $playhand = $game->getPlayHand();
            $game->discardPlayHand();
            ScreenDisplay::addScreenMessage($game, true, "discard  " . nicePrint($playhand), "discards " . sizeof($playhand) . " cards");
        }

        $game->setPhase(Phase_Sleep);

        //the waiting function
        $users_replies = MySocket::getUsersReplies($game);
        foreach ($users_replies as $name => $output) {

            $answer = $output[0];
            if ($answer == "Yes") {
                $bane = $game->getCardInHand($bane, $name);
                if ($bane)
                    ScreenDisplay::addScreenMessage($game, true, "reveal " . nicePrint($bane)." the bane card", "reveals  " . ScreenDisplay::$LMSG." the bane card", $name);
                else {
                    $curse = $game->moveCardFromPileToPile("Curse", BoardCards, DiscardPile, $name);
                    ScreenDisplay::addScreenMessage($game, true, "dont reveal a bain card so you gain " . nicePrint($curse), "doesnt reveal a bane card so he gains " . ScreenDisplay::$LMSG, $name);
                }
            } else {
                $curse = $game->moveCardFromPileToPile("Curse", BoardCards, DiscardPile, $name);
                ScreenDisplay::addScreenMessage($game, true, "dont reveal a bain card so you gain " . nicePrint($curse), "doesnt reveal a bane card so he gains " . ScreenDisplay::$LMSG, $name);
            }
        }
        $game->cardActionFinished();
        return true;
    }

    public function boardSetup(Game $game) {
        $game->addBaneCard();
        return true;
    }

}

?>